package cn.yunhe.entity;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.util.Date;

/**
 * 验证规则注解
 * springMVC只提供校验 不提供实现
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Transaction {

    //产品编号

    @NotNull
    private Integer productId;

    //用户编号

    @NotNull
    private Integer userId;

    //交易日期

    @Future
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull
    private Date date;

    //交易价格

    @NotNull
    @DecimalMin(value = "0.1")
    private Double price;

    //交易数量

    @Min(1)
    @Max(100)
    private Integer quantity;

    //总价

    @NotNull
    @DecimalMax("50000.0")
    @DecimalMin("1.00")
    private Double amount;

    //邮件

    @NotNull
    @Pattern(regexp = "/^\\\\w+([-+.]\\\\w+)*@\\\\w+([-.]\\\\w+)*\\\\.\\\\w+([-.]\\\\w+)*$/", message = "格式不对")
    private String email;

    //备注

    @Size(min = 0, max = 256)  //字符
    private String note;
}
